#ifndef IDENTTRACKER_H
#define IDENTTRACKER_H

#include <opencv2/core.hpp>
#include <opencv2/tracking.hpp>
#include "source/logger.h"

class IdentTracker
{
public:
    IdentTracker(float scaleFactor);
    ~IdentTracker();


    void initTemplate(const cv::Mat& templateImg,const cv::Rect &roi);
    void setScaleFactor(double scaleFactor);
    bool track(const cv::Mat& frame, cv::Rect2d& roi);

    void disableKCF();
    void enableKCF();

    void setEnablePreTracking(bool enablePreTracking_);
    bool getEnablePreTracking() const {return enablePreTracking;};

    void setcaleFactor(float scaleFactor_);
    float getScaleFactor() const {return scaleFactor;};

    bool getisInit() const {return isInit;};
    float getsimilarity() const {return similarity_;};

    bool trackv2(const cv::Mat &frame, cv::Rect2d &roi);
protected:
    bool isInit;
    bool enablePreTracking;
    float scaleFactor;
    float similarity_;
    cv::Ptr<cv::Tracker> tracker;
    cv::Mat ident_Img;
    cv::Rect ident_roi;
    double scaleFactor_;
    virtual void initialize(const cv::Mat& templateImg, const cv::Rect& roi = cv::Rect());
    virtual cv::Rect2d detectAndMatch(const cv::Mat& frame , float &Similarity) ; // 子类实现具体的检测和匹配
    void initializeKCF(const cv::Mat& frame, const cv::Rect2d& roi);
    cv::Rect2d scaleRect(const cv::Rect2d& rect, double scale) const;
    void scaleImage(const cv::Mat& src, cv::Mat& dst, double scale) const;
    std::mutex mutex;
};

#endif // IDENTTRACKER_H
